package org.yuanqiframework.yuanqi.web.mq;

import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.yuanqiframework.yuanqi.web.mq.handle.ConfirmCallback;
import org.yuanqiframework.yuanqi.web.mq.handle.ReturnsCallback;

@ConditionalOnClass(RabbitTemplate.class)
@Configuration
public class RabbitConfig {

    @Bean
    public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
        RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
        // 可以在这里进行一些额外的配置，例如消息转换器
        rabbitTemplate.setConfirmCallback(new ConfirmCallback());
        rabbitTemplate.setReturnsCallback(new ReturnsCallback());
        rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
        return rabbitTemplate;
    }
}
